package dp;

public class ds416 {
    public static void main(String[] args) {
        System.out.println(canPartition(new int[]{1, 2, 11, 5}));
    }
    public static boolean canPartition(int[] nums) {
        int sum = 0;
        for (int i : nums) {
            sum += i;
        }
        if(sum % 2 != 0)
            return false;
        int tar = sum / 2;
        int[] dp = new int[tar + 1];
        for (int i = 0; i < nums.length; i++) {
            for (int j = tar; j >= nums[i] ; j--) {
                dp[j] = Math.max(dp[j], dp[j - nums[i]] + nums[i]);
            }
        }
        return dp[tar] == tar;
    }
}
